package com.bayair.doctor.adapter;

import android.net.Uri;
import android.text.TextUtils;
import android.view.View;

import androidx.annotation.Nullable;

import com.bayair.doctor.R;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.tencent.qcloud.tim.uikit.component.picture.imageEngine.impl.GlideEngine;
import com.tencent.qcloud.tim.uikit.modules.contact.ContactItemBean;
import com.tencent.qcloud.tim.uikit.modules.conversation.LabelLinearLayout;

import java.util.List;

public class InquiryAdapter extends BaseQuickAdapter<ContactItemBean, BaseViewHolder> {

    public InquiryAdapter(@Nullable List<ContactItemBean> data) {
        super(R.layout.item_inquiry, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, ContactItemBean contactBean) {
        //设置头像
        if (TextUtils.isEmpty(contactBean.getAvatarurl())) {
            if (contactBean.isGroup()) {
                helper.setImageResource(R.id.iv_inquiry_avatar,R.drawable.default_head);
            } else {
                helper.setImageResource(R.id.iv_inquiry_avatar,R.drawable.default_user_icon);
            }
        } else {
            GlideEngine.loadImage(helper.getView(R.id.iv_inquiry_avatar), Uri.parse(contactBean.getAvatarurl()));
        }

        //设置名称
        if (!TextUtils.isEmpty(contactBean.getRemark())) {
            helper.setText(R.id.tv_inquiry_name, contactBean.getRemark());
        } else if (!TextUtils.isEmpty(contactBean.getNickname())) {
            helper.setText(R.id.tv_inquiry_name, contactBean.getNickname());
        } else {
            helper.setText(R.id.tv_inquiry_name, contactBean.getId());
        }

        //设置是否在服务中
        LabelLinearLayout view = helper.getView(R.id.item_contact);
        if (contactBean.isInServer()) {
            view.setLabelVisual(true);
        } else {
            view.setLabelVisual(false);
        }

        //未读计数
        helper.getView(R.id.tv_inquir_unread).setVisibility(View.GONE);
    }
}
